﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Wpf="clr-namespace:Sentinel.Support.Wpf"
             xmlns:Converters="clr-namespace:Sentinel.Support.Converters"
             mc:Ignorable="d"
             x:Class="Sentinel.Views.Gui.MultipleViewFrame"
             x:Name="UserControl"
             MinHeight="100"
             MinWidth="300">

    <UserControl.Resources>
        <Style TargetType="{x:Type Image}">
            <Setter Property="RenderOptions.BitmapScalingMode"
                    Value="NearestNeighbor" />
        </Style>

        <Style TargetType="{x:Type Image}"
               x:Key="toolbarCheckboxImageStyle">
            <Setter Property="RenderOptions.BitmapScalingMode"
                    Value="NearestNeighbor" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type CheckBox}}}"
                             Value="False">
                    <Setter Property="Opacity"
                            Value="0.50" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Converters:TypeToSmallImageConverter x:Key="typeToSmallImage"/>
        <Converters:ImageLibraryConverter x:Key="ImageLibrary" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ToolBarTray Grid.Row="0"
                     Grid.Column="0"
                     Grid.ColumnSpan="2"
                     x:Name="toolBarPanel1">
           
            <Wpf:DataBoundToolbar x:Name="PrimaryToolbar"
                                  ItemsSource="{Binding PrimaryView.ToolbarItems}"
                                  Width="Auto"
                                  HorizontalContentAlignment="Center">
                <Wpf:DataBoundToolbar.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <!-- Can be either a button or checkbox, define both and show/collapse on the DataTrigger -->
                            <CheckBox x:Name="primaryViewCheckbox"
                                      Style="{DynamicResource {x:Static ToolBar.CheckBoxStyleKey}}"
                                      IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                      Command="{Binding Command}"
                                      Height="22">
                                <CheckBox.ToolTip>
                                    <TextBlock Text="{Binding Tooltip}" />
                                </CheckBox.ToolTip>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding ImageIdentifier, Converter={StaticResource ImageLibrary}}"
                                           Style="{StaticResource toolbarCheckboxImageStyle}"
                                           Width="16"
                                           Height="16" />
                                    <TextBlock Text="{Binding Label}"
                                               Margin="3,0"
                                               VerticalAlignment="Center"
                                               Width="Auto" />
                                </StackPanel>
                            </CheckBox>
                            
                            <Button x:Name="primaryViewButton"
                                    Visibility="Collapsed"
                                    Style="{DynamicResource {x:Static ToolBar.ButtonStyleKey}}"
                                    Command="{Binding Command}"
                                    Height="22">
                                <Button.ToolTip>
                                    <TextBlock Text="{Binding Tooltip}" />
                                </Button.ToolTip>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding ImageIdentifier, Converter={StaticResource ImageLibrary}}"
                                           Width="16"
                                           Height="16" />
                                    <TextBlock Text="{Binding Label}"
                                               Margin="3,0"
                                               VerticalAlignment="Center"
                                               Width="Auto" />
                                </StackPanel>
                            </Button>
                        </StackPanel>
                        
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding CanCheck}"
                                         Value="false">
                                <Setter TargetName="primaryViewButton"
                                        Property="Visibility"
                                        Value="Visible" />
                                <Setter TargetName="primaryViewCheckbox"
                                        Property="Visibility"
                                        Value="Collapsed" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                        
                    </DataTemplate>
                </Wpf:DataBoundToolbar.ItemTemplate>
            </Wpf:DataBoundToolbar>

            <!--<ToolBar Header="Search : "
                     Width="Auto"
                     VerticalContentAlignment="Center">
                <TextBox Width="100"
                         Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
                <Label Content=" in "
                       VerticalAlignment="Center"
                       Margin="5,0"
                       HorizontalAlignment="Center" />
                <ComboBox SelectedIndex="1"
                          IsEditable="False"
                          IsEnabled="False"
                          Width="75">
                    <ComboBox.Items>
                        <ComboBoxItem Content="Type"/>
                        <ComboBoxItem Content="System" />
                        <ComboBoxItem Content="Description" />
                    </ComboBox.Items>
                </ComboBox>                
            </ToolBar>-->
            
        </ToolBarTray>

        <DockPanel Grid.Row="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="5" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <DockPanel x:Name="first"
                           Grid.Row="0"
                           Grid.Column="0"
                           Grid.ColumnSpan="1"
                           Grid.RowSpan="3">
                    <Label DockPanel.Dock="Top"
                           Background="CornflowerBlue"
                           Content="{Binding PrimaryTitle}"
                           FontWeight="Bold"
                           Foreground="White"
                           FontSize="9" />
                    <ContentControl Content="{Binding PrimaryView.Presenter}" />
                </DockPanel>
                <GridSplitter x:Name="splitter"
                              ResizeBehavior="PreviousAndNext"
                              Width="5"
                              Grid.Row="0"
                              Grid.Column="1"
                              Grid.RowSpan="3"
                              Grid.ColumnSpan="1" />
                <DockPanel x:Name="second"
                           Grid.Column="2"
                           Grid.ColumnSpan="1"
                           Grid.RowSpan="3"
                           Grid.Row="0">
                    <Label DockPanel.Dock="Top"
                           Background="CornflowerBlue"
                           Content="{Binding SecondaryTitle}"
                           FontWeight="Bold"
                           Foreground="White"
                           FontSize="9" />
                    <ContentControl Content="{Binding SecondaryView.Presenter}" />
                </DockPanel>
            </Grid>
        </DockPanel>
        <TextBlock Grid.Row="4"
                   Grid.ColumnSpan="2"
                   Margin="0,2,0,0"
                   Text="{Binding PrimaryView.Status}" />
    </Grid>
</UserControl>